$(function(){
    var getValue = decodeURIComponent(location.search.split("=")[1]);
    // console.log('getValue: ', getValue);
    var url = `http://192.168.4.18:3000/comment/music?id=${getValue}&limit=1`;
    $.ajax({
        method:"get",
        url,
        success: function(res) {
            // console.log(res);
            handData(res);
        }
    })
    function handData(item){
        item.hotComments.forEach(function(value){
            var time = times(value.time);
            // console.log(value);
            var html = `<div class="comment">
                    <img class="commentImg" src=${value.user.avatarUrl} alt="">
                    <div>
                        <p>
                            <a href=""><span  class="commentId">${value.user.nickname}</span></a>
                            <span class="commentContent">：${value.content}</span>
                        </p>
                        <p class="commentTime">${time}</p>
                    </div>
                </div>`
            $(".commentBody").append(html);
        })
    }
    
    function times(test){
        var gapTime = new Date(test);
        // console.log(gapTime);
        var years = minNumber( gapTime.getFullYear());
        var mouths = minNumber(gapTime.getMonth()+1);
        var days = minNumber(gapTime.getDate());
        var detailTime = gapTime.getTimezoneOffset();
        var res = `${years}年${mouths}月${days}日`
        return res;
    }

    // 补零
    function minNumber(num){
        if(num<10){
            num = "0"+num;
        }
        return num;
    }
})